﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerOrderDetails.aspx.cs" Inherits="Project3.CustomerOrderDetails" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:TextBox ID="ParameterText" runat="server"></asp:TextBox>
        <asp:Button ID="SearchButton" runat="server" Text="Search" 
            onclick="SearchButton_Click" />
        <asp:Button ID="ResetButton" runat="server" Text="Reset" 
            onclick="ResetButton_Click" />
    
    </div>
    <asp:Repeater ID="RepeaterSearch" runat="server">
   <HeaderTemplate><table width="600px" border="1"></HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                        <td><h3><b>Customer</b></h3></td>
                        <td><h3><b>Adress</b></h3></td>
                    </tr> 
                    <tr>
                        <td>
                            <%# Eval("CustomerID") %><br />
                            <h3><%# Eval("ContactName") %></h3><br />
                            <%# Eval("CompanyName") %><br />
                            <%# Eval("Phone") %><br />
                            <%# Eval("Fax")%><br />
                        </td>
                        <td>
                            <%# Eval("Address") %><br />
                            <%# Eval("City")%>, <%# Eval("Country")%><br />
                            <%# Eval("PostalCode") %>
                        </td>                      
                     </tr>
                    </ItemTemplate>
                <FooterTemplate></table></FooterTemplate>
    </asp:Repeater>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByParam" 
        TypeName="Project3.CustomerOrderDetailsDataSetTableAdapters.DataTable1TableAdapter">
        <SelectParameters>
            <asp:Parameter Name="p" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>" 
        SelectCommand="SELECT [CustomerID],[ContactName], [CompanyName], [Phone], [Fax], [Address], [City], [Country], [PostalCode] FROM [Customers]">
    </asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" DataKeyNames="CustomerID" 
        DataSourceID="SqlDataSource1" onrowdatabound="GridView1_RowDataBound">
        <Columns>
            <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" 
                SortExpression="CustomerID" />
            
            <asp:TemplateField>
                <HeaderTemplate>Customer</HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("CustomerID") %><br />
                    <h4><%# Eval("ContactName") %></h4><br />
                    <%# Eval("CompanyName") %><br />
                    <%# Eval("Phone") %><br />
                    <%# Eval("Fax")%>
                    <asp:GridView ID="GridView3" runat="server">
                        <Columns>
                                <asp:BoundField DataField="value2" HeaderText="value2" ReadOnly="True" SortExpression="value2" />
                        </Columns>
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>" SelectCommand="SELECT     SUM(t4.value) AS Amount
FROM         (SELECT     UnitPrice * CONVERT(Decimal(29, 4), Quantity) AS [value], CustomerID, value AS value2
                       FROM          (SELECT     t1.ContactName AS value, t2.UnitPrice, t2.Quantity, t1.CustomerID
                                               FROM          Orders AS t0 LEFT OUTER JOIN
                                                                      Customers AS t1 ON t1.CustomerID = t0.[CustomerID] LEFT OUTER JOIN
                                                                      [Order Details] AS t2 ON t2.OrderID = t0.[OrderID]) AS t3) AS t4
WHERE     (CustomerID LIKE @CustomerID )
GROUP BY value2">
                        <SelectParameters>
                            <asp:Parameter Name="CustomerID" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <br />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>Address</HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Address") %><br />
                    <%# Eval("City")%>, <%# Eval("Country")%><br />
                    <%# Eval("PostalCode") %>
                </ItemTemplate>
            </asp:TemplateField>
        
            <asp:TemplateField AccessibleHeaderText="Orders">
                <ItemTemplate>
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>" 
                        SelectCommand="SELECT [Orders].[OrderID], [OrderDate], [Products].[ProductID], [ProductName], [Order Details].[UnitPrice], [Quantity], [Discount], (Quantity * [Order Details].[UnitPrice]) AS SubTotal FROM [Orders] JOIN [Order Details] ON [Order Details].[OrderID] = [Orders].[OrderID] JOIN [Products] ON [Products].[ProductID] = [Order Details].[ProductID] WHERE ([CustomerID] = @CustomerID)">
                        <SelectParameters>
                            <asp:Parameter Name="CustomerID" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                        DataKeyNames="OrderID" DataSourceID="SqlDataSource2">
                        <Columns>
                            
                            <asp:BoundField DataField="OrderDate" HeaderText="OrderDate" 
                                SortExpression="OrderDate" />
                                <asp:BoundField DataField="ProductID" HeaderText="ProductID" 
                                SortExpression="ProductID" />
                                <asp:BoundField DataField="ProductName" HeaderText="ProductName" 
                                SortExpression="ProductName" />
                                <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" 
                                SortExpression="UnitPrice" />
                                <asp:BoundField DataField="Quantity" HeaderText="Quantity" 
                                SortExpression="Quantity" />
                                <asp:BoundField DataField="Discount" HeaderText="Discount" 
                                SortExpression="Discount" />
                                <asp:BoundField DataField="SubTotal" HeaderText="SubTotal" 
                                SortExpression="SubTotal" />
                        </Columns>
                    </asp:GridView>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <RowStyle VerticalAlign="Top" />
    </asp:GridView>
    </form>
</body>
</html>
